package com.sitanyun.merchant.guide.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.bean.BankBean;
import com.sitanyun.merchant.guide.weiht.StringReplaceUtil;

/**
 * Created by jzl
 * on 2022/1/14.
 * 银行卡列表
 */
public class BankAdapter extends BaseQuickAdapter<BankBean.DataBean, BaseViewHolder> {
    private int positions=-1 ;//用于记录当前位置
    public BankAdapter(Context context) {
        super(R.layout.bank_item);
        this.mContext = context;
    }
    /*
     * 用于设置当前位置
     */
    public  void setPosition(int position) {
        this.positions = position;
    }
    @Override
    protected void convert(BaseViewHolder helper, BankBean.DataBean item) {

      if (item.getBankName().isEmpty()){
          helper.setText(R.id.bank_name,"银行卡");
      }else {
          helper.setText(R.id.bank_name,item.getBankName());
      }
        helper  .setText(R.id.bank_username,item.getCardOwner());

        helper.addOnClickListener(R.id.bank_delete);
        helper.addOnClickListener(R.id.look);
        helper.addOnClickListener(R.id.bank_usernumber);
        TextView jq =helper.getView(R.id.jq);
       if (helper.getPosition()==0){
           jq.setVisibility(View.VISIBLE);
        }else {
           jq.setVisibility(View.GONE);
       }
        ImageView looks= helper.getView(R.id.look);

       //睁眼
            if (positions==1){
                if (item.getDelFlag().equals("0")){
                    Glide.with(mContext).load(R.mipmap.nolook).into(looks);
                    helper.setText(R.id.bank_usernumber, StringReplaceUtil.bankCardReplaceWithStar(item.getBankCardNum()));
                }else {
                    Glide.with(mContext).load(R.mipmap.look).into(looks);
                    helper.setText(R.id.bank_usernumber, item.getBankCardNum());
                }

            }else {
                if (item.getDelFlag().equals("0")){
                    Glide.with(mContext).load(R.mipmap.nolook).into(looks);
                    helper.setText(R.id.bank_usernumber, StringReplaceUtil.bankCardReplaceWithStar(item.getBankCardNum()));

                }else {
                    Glide.with(mContext).load(R.mipmap.look).into(looks);
                    helper.setText(R.id.bank_usernumber, item.getBankCardNum());

                }

            }


    }

}
